package com.libgdxbar.pvzlikegame.objects;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Pool;
import com.libgdxbar.pvzlikegame.entities.LocationEntity;
import com.libgdxbar.pvzlikegame.objects.bullets.SampleBullet;

import org.libgdxbar.projects.interfaces.renderer.IShapeRender;

// 最简示例 植物类
// 继承 LocationEntity 即包含位置的实体
// 实现 ShapeRenderable 接口 使用 ShapeRenderer 渲染图形
public class SampleShapePlant extends LocationEntity implements IShapeRender {
	Pool<SampleBullet> bulletsPool;
	float shootDelta = 0.0f;

	public SampleShapePlant(float x, float y, Pool<SampleBullet> bulletsPool) {
		super(x, y);
		this.bulletsPool = bulletsPool;
	}

	// 实现渲染方法
	@Override
	public void render(ShapeRenderer renderer) {
		renderer.setColor(Color.GREEN);
		Vector2 position = getPosition();
		renderer.rect(position.x, position.y, 50, 50);
	}

	// 实现植物逻辑
	@Override
	public void run(float delta) {
		super.run(delta);
		shootDelta += delta;
		if (shootDelta >= 1.0f) {
			SampleBullet bullet = bulletsPool.obtain();
			Vector2 position = getPosition();
			bullet.init(position.x + 40, position.y + 20, 100, 0);
			shootDelta = 0.0f;
		}
	}
}
